var flag = false;
//默认页码
var default_pageNo = 1;
//默认每页呈现的记录数
var default_pageSize = 20;
$( function ()
{
    //初始化地区选择器
    var $citypicker1 = $('#SenderProCityAres');
    
    var $citypicker2 = $('#AcceptProCityArea');
   $( '.praise_type label' ).click( function ()
    {
        $( this ).addClass( 'checked' ).siblings().removeClass( 'checked' );
    } );
    

    //判断身份证号格式
    $( "#IdCard" ).on( "change", function ()
    {
        var _Y_NEmail = document.getElementById( "_Y_NEmail" );
        if ( $( "#IdCard" ).val() != "" )
        {

            var _Emailval = InputVCheck( 'IdCard', 7, $( "#IdCard" ).val() )
            if ( _Emailval )
            {
//              _Y_NEmail.textContent = "✔验证已通过"
//              _Y_NEmail.style = "color:green";
            }
            else if ( !_Emailval )
            {
               layer.alert('身份证号错误!');
            }
        } else
        {
//          _Y_NEmail.textContent = "";
        }
    } );

    //判断重量
    $( "#Articleweight" ).on( "change", function ()
    {
        var _Y_N_Articleweight = document.getElementById( "_Y_N_Articleweight" );
        if ( $( "#Articleweight" ).val() != "" )
        {
            debugger;           
            var _Emailval = $( "#Articleweight" ).val()         
            if ( _Emailval <= 50 && _Emailval >= 0 && parseInt( _Emailval ) == _Emailval )
            {
//              _Y_N_Articleweight.textContent = "✔"
//              _Y_N_Articleweight.style = "color:green";
            }
            else
            {
//              _Y_N_Articleweight.textContent = "✘,重量为整数";
//              _Y_N_Articleweight.style = "color:Red";
//              alert('重量为整数');
            }
        } else
        {
            _Y_N_Articleweight.textContent = "";
        }
    } );

    //判断发件人/收件人手机号格式
    $( "#SenderPhone" ).on( "change", function ()
    {
        //发件人手机号格式判断
        var senderPhone = $( "#SenderPhone" ).val();
        $.ajax( {
         url: "http://localhost:8080/A1_BILL/O2OOrder/getClientInfo.do?callback=?&USER_NAME=WEM1&PASSWORD=1",
         // url: "http://10.16.170.37:8080/A1_INTE/benniaoOrder/benO2OOrder.do?callback=?&content="+encodeURI(encodeURI(strDetails)),
         data: {"PHONE":senderPhone},
            type: 'POST',
            async: false,
            dataType: "json",
		    jsonp: "callback",//传递给请求处理程序或页面的，用以获得jsonp回调函数名的参数名(一般默认为:callback)
		    jsonpCallback:"callback",//自定义的jsonp回调函数名，默认未jquery自动生成的随机函数名，也可以写“?”jquery会自动处理
        	//crossDomain: true,
        	//scriptCharset: "utf-8",
            success: function (result)
            {
            	    if(result.returnType=="SUCCESS"){
//          	    	 var SenderPhone = $( "#SenderPhone" ).val();
// var SenderName = $( "#SenderName" ).val();
// var SenderMobile= $( "#SenderMobile" ).val();
// var SenderAddress = $( "#SenderAddress" ).val();
$( "#SenderName" ).val(result.returnValue["contact"]);
   $( "#SenderAddress" ).val(result.returnValue["address"]);
//              	    $("#user").val("输入手机号码或邮箱")
            	    }else{
            		    
             	}
            }, 
            failed: function ()
            {
               
            }
        } )
//      var _Y_N_SenderPhone = document.getElementById( "_Y_N_SenderPhone" );
//      if ( senderPhone != "" )
//      {
//          var senderPhoneResult = InputVCheck( 'SenderPhone', 0, senderPhone )
//          if ( senderPhoneResult )
//          {
//              _Y_N_SenderPhone.textContent = "✔"
//              _Y_N_SenderPhone.style = "color:green;width:10px";
//          }
//          else if ( !senderPhoneResult )
//          {
//              _Y_N_SenderPhone.textContent = "✘"
//              _Y_N_SenderPhone.style = "color:Red;width:10px";
//          }
//      } else
//      {
//          _Y_N_SenderPhone.textContent = "";
//      }
//      //收件人手机号格式判断
//      var acceptPhone = $( "#AcceptPhone" ).val();
//      var _Y_N_AcceptPhone = document.getElementById( "_Y_N_AcceptPhone" );
//      if ( acceptPhone != "" )
//      {
//          var acceptPhoneResult = InputVCheck( 'AcceptPhone', 0, acceptPhone )
//          if ( acceptPhoneResult )
//          {
//              _Y_N_AcceptPhone.textContent = "✔"
//              _Y_N_AcceptPhone.style = "color:green;width:10px";
//          }
//          else if ( !acceptPhoneResult )
//          {
//              _Y_N_AcceptPhone.textContent = "✘"
//              _Y_N_AcceptPhone.style = "color:Red;width:10px";
//          }
//      } else
//      {
//          _Y_N_AcceptPhone.textContent = "";
//      }
    } );
     $( "#AcceptPhone" ).on( "change", function ()
    {
        //发件人手机号格式判断
        var senderPhone = $( "#AcceptPhone" ).val();
        $.ajax( {
         url: "http://localhost:8080/A1_BILL/O2OOrder/getClientInfo.do?callback=?&USER_NAME=WEM1&PASSWORD=1",
         // url: "http://10.16.170.37:8080/A1_INTE/benniaoOrder/benO2OOrder.do?callback=?&content="+encodeURI(encodeURI(strDetails)),
         data: {"PHONE":senderPhone},
            type: 'POST',
            async: false,
            dataType: "json",
		    jsonp: "callback",//传递给请求处理程序或页面的，用以获得jsonp回调函数名的参数名(一般默认为:callback)
		    jsonpCallback:"callback",//自定义的jsonp回调函数名，默认未jquery自动生成的随机函数名，也可以写“?”jquery会自动处理
        	//crossDomain: true,
        	//scriptCharset: "utf-8",
            success: function (result)
            {
            	    if(result.returnType=="SUCCESS"){
//          	    	 var SenderPhone = $( "#SenderPhone" ).val();
// var SenderName = $( "#SenderName" ).val();
// var SenderMobile= $( "#SenderMobile" ).val();
// var SenderAddress = $( "#SenderAddress" ).val();
$( "#AcceptName" ).val(result.returnValue["contact"]);
   $( "#AcceptAddress" ).val(result.returnValue["address"]);
//              	    $("#user").val("输入手机号码或邮箱")
            	    }else{
            		    
             	}
            }, 
            failed: function ()
            {
               
            }
        } )
//      var _Y_N_SenderPhone = document.getElementById( "_Y_N_SenderPhone" );
//      if ( senderPhone != "" )
//      {
//          var senderPhoneResult = InputVCheck( 'SenderPhone', 0, senderPhone )
//          if ( senderPhoneResult )
//          {
//              _Y_N_SenderPhone.textContent = "✔"
//              _Y_N_SenderPhone.style = "color:green;width:10px";
//          }
//          else if ( !senderPhoneResult )
//          {
//              _Y_N_SenderPhone.textContent = "✘"
//              _Y_N_SenderPhone.style = "color:Red;width:10px";
//          }
//      } else
//      {
//          _Y_N_SenderPhone.textContent = "";
//      }
//      //收件人手机号格式判断
//      var acceptPhone = $( "#AcceptPhone" ).val();
//      var _Y_N_AcceptPhone = document.getElementById( "_Y_N_AcceptPhone" );
//      if ( acceptPhone != "" )
//      {
//          var acceptPhoneResult = InputVCheck( 'AcceptPhone', 0, acceptPhone )
//          if ( acceptPhoneResult )
//          {
//              _Y_N_AcceptPhone.textContent = "✔"
//              _Y_N_AcceptPhone.style = "color:green;width:10px";
//          }
//          else if ( !acceptPhoneResult )
//          {
//              _Y_N_AcceptPhone.textContent = "✘"
//              _Y_N_AcceptPhone.style = "color:Red;width:10px";
//          }
//      } else
//      {
//          _Y_N_AcceptPhone.textContent = "";
//      }
    } );
    //发件人座机号,收件人座机号判断
    $( "#SenderMobile,#AcceptMobile" ).on( "change", function ()
    {
        //发件人座机号格式判断
        var senderPhone = $( "#SenderMobile" ).val();
        var _Y_N_SenderPhone = document.getElementById( "_Y_N_SenderMobile" );
        if ( senderPhone != "" )
        {
            var senderPhoneResult = InputVCheck( 'SenderMobile', 1, senderPhone )
            if ( senderPhoneResult )
            {
                _Y_N_SenderPhone.textContent = "✔"
                _Y_N_SenderPhone.style = "color:green;width:10px";
            }
            else if ( !senderPhoneResult )
            {
                _Y_N_SenderPhone.textContent = "✘"
                _Y_N_SenderPhone.style = "color:Red;width:10px";
            }
        } else
        {
            _Y_N_SenderPhone.textContent = "";
        }
        //收件人座机号格式判断
        var acceptPhone = $( "#AcceptMobile" ).val();
        var _Y_N_AcceptPhone = document.getElementById( "_Y_N_AcceptMobile" );
        if ( acceptPhone != "" )
        {
            var acceptPhoneResult = InputVCheck( 'AcceptMobile', 1, acceptPhone )
            if ( acceptPhoneResult )
            {
                _Y_N_AcceptPhone.textContent = "✔"
                _Y_N_AcceptPhone.style = "color:green;width:10px";
            }
            else if ( !acceptPhoneResult )
            {
                _Y_N_AcceptPhone.textContent = "✘"
                _Y_N_AcceptPhone.style = "color:Red;width:10px";
            }
        } else
        {
            _Y_N_AcceptPhone.textContent = "";
        }
    } )
    //限制文本框输入字符长度
    $( "#SenderPhone,#AcceptPhone" ).on( 'keyup', function ()
    {
        var value = $( this ).val();
        if ( value.length > 11 )
        {
            $( this ).val( GetStrSub( value, 11 ) );
        }
    } );
    //地区控件触发事件（绑定父元素，调用子元素，触发事件）
   $( "#SenderProCityAres" ).parent( '.area_box' ).on( "click", '.district dd a', function ()
    {
        LoadPageData();
        var Senderprivance = ""; //省份
        var Sendercity = "";//城市
        var Senderdistrict = "";//街道
        $( ".city-picker-span" ).find( "span.title" ).find( "span.select-item" ).each( function ( index, element )
        {
            var type = $( element ).attr( "data-count" );
            var code = $( element ).attr( "data-code" );
            if ( type === "province" )
            {
                Senderprivance = code;
            }
            else if ( type === "city" )
            {
                Sendercity = code;
            }
            else if ( type === "district" )
            {
                Senderdistrict = code;
            }
        } );
        var SenderProCityAresId = Senderprivance + "-" + Sendercity + "-" + Senderdistrict;
        $( "#SenderProCityAresId" ).val( SenderProCityAresId );
    } );
  $( "#AcceptProCityArea" ).parent('.area_box' ).on( "click", '.district dd a', function ()
    {
        var Acceptprivance = ""; //省份
        var Acceptcity = "";//城市
        var Acceptdistrict = "";//街道
        $( ".city-picker-span" ).find( "span.title" ).find( "span.select-item" ).each( function ( index, element )
        {
            var type = $( element ).attr( "data-count" );
            var code = $( element ).attr( "data-code" );
            if ( type === "province" )
            {
                Acceptprivance = code;
            }
            else if ( type === "city" )
            {
                Acceptcity = code;
            }
            else if ( type === "district" )
            {
                Acceptdistrict = code;
            }
        } );
        var AcceptProCityAreaId = Acceptprivance + "-" + Acceptcity + "-" + Acceptdistrict;
        $( "#AcceptProCityAreaId" ).val( AcceptProCityAreaId );
    } );
   

    $( ".layer-close" ).click( function ()
    {
        //关闭弹出框并刷新页面
        showHide();
    } );
} )

//关闭界面
function closeWindow( code, fullName )
{
    //关闭弹出框并给隐藏域赋值
    showHide();
    $( "#companyName" ).show();
    $( "#companyName" ).text( "下单到 " + fullName + "(" + code + ")" );
    $( "#TakeCompanyCode" ).val( code )
}
//打开界面
function showHide()
{
    $( ".layer-shade" ).toggle();
}
//省市区分页数据
function LoadPageData()
{
    var privance = ""; //省份
    var city = "";//城市
    var district = "";//街道
    $( ".city-picker-span" ).find( "span.title" ).find( "span.select-item" ).each( function ( index, element )
    {
        var type = $( element ).attr( "data-count" );
        var code = $( element ).attr( "data-code" );
        if ( type === "province" )
        {
            privance = code;
        }
        else if ( type === "city" )
        {
            city = code;
        }
        else if ( type === "district" )
        {
            district = code;
        }
    } );
    return false;
}

//截取字符串
function GetStrSub( str, lth )
{
    var resultStr = "";
    if ( str == undefined || str == "" )
    {
        resultStr = "";
    }
    else
    {
        if ( str.length > lth )
        {
            resultStr = str.substring( 0, lth );
        }
        else
        {
            resultStr = str;
        }
    }
    return resultStr;
}
//提交前校验
function submitForm( o )
{
//


if ($("#xieyi").get(0).checked) {
    // do something
}else{
	layer.alert( "请查看用户条款，同意后才能下单!" );
	return false;
}
    var SenderProCityAres = $( "#SenderProCityAres" ).val();
    var Articleweight = $( "#Articleweight" ).val()
    var SenderAddress = $( "#SenderAddress" ).val();
    var SenderName = $( "#SenderName" ).val();
    var AcceptProCityArea = $( "#AcceptProCityArea" ).val();
    var AcceptAddress = $( "#AcceptAddress" ).val();
    var AcceptName = $( "#AcceptName" ).val();
    var Email = $( "#IdCard" ).val();
    //判断选择的日期是否大于今天的日期
    if ( Articleweight > 50 || Articleweight < 0 )
    {
        layer.alert( "重量不得大于50kg或小于0kg" );
        return false;
    }
    ////校验所有的数据是否有值,如果有的话提示
      if ( SenderProCityAres == "" || IdCard == "" || SenderAddress == "" || SenderName == "" || AcceptProCityArea == "" || AcceptAddress == "" || AcceptName == "" )
      {
          layer.alert( "尊敬的客户,请补全信息!" )
          return false;
      }
    //校验所有的数据是否有值,如果有的话提示
    if ( SenderProCityAres == "" || SenderAddress == "" || AcceptProCityArea == "" || AcceptAddress == "" )
    {
        layer.alert( "抱歉,收发件地址及详细地址必填" )
        return false;
    }
    if ( SenderName == "" || AcceptName == "" )
    {
        layer.alert( "抱歉,寄件人姓名及收件人姓名必填" )
        return false;
    }
    //校验手机号和座机号是否至少填写了一项
    if ( $( "#SenderPhone" ).val() == "" && $( "#SenderMobile" ).val() == "" )
    {
        layer.alert( "抱歉,发件人手机号和座机号码至少填写一项" )
        return false;
    }
    if ( $( "#AcceptPhone" ).val() == "" && $( "#AcceptMobile" ).val() == "" )
    {
        layer.alert( "抱歉,收件人手机号和座机号至少填写一项" );
        return false;
    }
    //开始校验所有的内容格式是否正确
    //校验城市列表是否已经全部选择完毕,是否存在xx省-xx市-?的情况.
    var Senderlen = SenderProCityAres.split( '/' ).length - 1;
    var Acceptlen = AcceptProCityArea.split( '/' ).length - 1;
    if ( Senderlen != 2 )
    {
        layer.alert( "抱歉您的发件区域地址没有选择完毕" )
        return false;
    }
    if ( Acceptlen != 2 )
    {
        layer.alert( "抱歉您的收件区域地址没有选择完毕" )
        return false;
    }
    //校验城市列表是否已经全部选择完毕,是否含有其他区字样.
    var Senderlen = SenderProCityAres.split( '/' );
    var Acceptlen = AcceptProCityArea.split( '/' );
    if ( Senderlen[2]=="其他区" )
    {
        layer.alert( "抱歉发件区域地址不允许有其他区字样" )
        return false;
    }
    if ( Acceptlen[2] == "其他区" )
    {
        layer.alert( "抱歉您的收件区域地址不允许有其他区字样" )
        return false;
    }
    //提交前又一次校验手机号和邮箱的格式,用户可能存在修改
    if ( !InputVCheck( 'SenderPhone', 0, $( "#SenderPhone" ).val() ) )
    {
        layer.alert( "抱歉发件人手机号格式不正确!" )
        return false;
    }
    if ( !InputVCheck( 'AcceptPhone', 0, $( "#AcceptPhone" ).val() ) )
    {
        layer.alert( "抱歉收件人手机号格式不正确!" )
        return false;
    }
    if ( !InputVCheck( 'SenderMobile', 1, $( "#SenderMobile" ).val() ) )
    {
        layer.alert( "抱歉发件人人座机号格式不正确!" )
        return false;
    }
    if ( !InputVCheck( 'AcceptMobile', 1, $( "#AcceptMobile" ).val() ) )
    {
        layer.alert( "抱歉收件人座机号格式不正确!" )
        return false;
    }
    if ( !InputVCheck( 'IdCard', 7, $( "#IdCard" ).val() ) )
    {
        layer.alert( "抱歉身份证号填写不正确!" )
        return false;
    }
    ajaxPostOrderCreate();
}
       

//Ajax请求验证
function ajaxPostOrderCreate()
{
   if ( flag )
    {
        return;
    }
    flag = true;
    //请求提交
    function dd()
    {
        
        // layer.alert( "正在提交中，请稍等~" );
       	layer.msg( '正在提交中，请稍等', { icon: 16, shade: 0.05 } );
       	//发件地址拆分省市区
       	var SenderAddressArray=$( "#SenderProCityAres" ).val().split('/');
       	var SenderAddress=$( "#SenderProCityAres" ).val().replace( /\//g, '' )+$( "#SenderAddress" ).val();
       	//收件地址拆分省市区
       	var AcceptAddressArray=$( "#AcceptProCityArea" ).val().split('/');
       	var AcceptAddress=$( "#AcceptProCityArea" ).val().replace( /\//g, '' )+$( "#AcceptAddress" ).val();
        var strDetails="<request>";
        strDetails+="<tms_service_code>BenNiao-001</tms_service_code>";
        strDetails+="<order_code></order_code>";
        strDetails+="<order_flag>36</order_flag>";
        strDetails+="<schedule_type>"+$("#timetype").val()+"</schedule_type>";
        strDetails+="<receiver_name>"+$( "#AcceptName" ).val()+"</receiver_name>";
        strDetails+="<receiver_province>"+AcceptAddressArray[0]+"</receiver_province>";
        strDetails+="<receiver_city>"+AcceptAddressArray[1]+"</receiver_city>";
        strDetails+="<receiver_district>"+AcceptAddressArray[2]+"</receiver_district>";
        strDetails+="<receiver_address>"+AcceptAddress+"</receiver_address>";
        strDetails+="<receiver_mobile>"+$( "#AcceptPhone" ).val()+"</receiver_mobile>";
        strDetails+="<receiver_phone>"+$( "#AcceptMobile" ).val()+"</receiver_phone>";
        strDetails+="<package_weight>"+$( "#Articleweight" ).val()+"</package_weight>";
        strDetails+="<sender_name>"+$( "#SenderName" ).val()+"</sender_name>";
        strDetails+="<sender_province>"+SenderAddressArray[0]+"</sender_province>";
        strDetails+="<sender_city>"+SenderAddressArray[1]+"</sender_city>";
        strDetails+="<sender_district>"+SenderAddressArray[2]+"</sender_district>";
        strDetails+="<sender_address>"+SenderAddress+"</sender_address>";
        strDetails+="<sender_mobile>"+$( "#SenderPhone" ).val()+"</sender_mobile>";
        strDetails+="<sender_phone>"+$( "#SenderMobile" ).val()+"</sender_phone>";
        strDetails+="<remark>"+$( "#IdCard" ).val()+"；物品类型:"+$("#goodsname").find("option:selected").text()+";用户输入重量"+$( "#Articleweight" ).val()+"</remark>";
        strDetails+="</request>";
        //请求
        $.ajax( {
            url: "http://a1inte.peitianxia.com/A1_INTE/benniaoOrder/benO2OOrder.do?callback=?&content="+encodeURI(encodeURI(strDetails)),
// url: "http://10.16.170.37:8080/A1_INTE/benniaoOrder/benO2OOrder.do?callback=?&content="+encodeURI(encodeURI(strDetails)),
            type: 'GET',
            async: false,
            dataType: "json",
		    jsonp: "callback",//传递给请求处理程序或页面的，用以获得jsonp回调函数名的参数名(一般默认为:callback)
		    jsonpCallback:"callback",//自定义的jsonp回调函数名，默认未jquery自动生成的随机函数名，也可以写“?”jquery会自动处理
        	//crossDomain: true,
        	//scriptCharset: "utf-8",
            success: function (result)
            {
            	if(result.returnType=="SUCCESS"){
                	layer.alert( "您的订单已下单成功！订单号是"+result.returnValue+"，请记住订单号，可用它跟踪物流状态");
                	saveClientInfo();
            	}else{
            		layer.alert( "您的订单下单失败！" );
            		flag = false;
            	}
                //alert( "您的订单：" + data.ResultValue + " 已下单成功！" )
                //flag = false;
            }, 
            failed: function ()
            {
            	layer.alert( "您的订单下单失败！" );
                flag = false;
            }
        } )
    }
    dd();
}
//保存客户新型
function saveClientInfo()
{
   var SenderPhone = $( "#SenderPhone" ).val();
   var SenderName = $( "#SenderName" ).val();
   var SenderMobile= $( "#SenderMobile" ).val();
   var SenderAddress = $( "#SenderAddress" ).val();
   var AcceptMobile = $( "#AcceptMobile" ).val();
   var AcceptPhone=$( "#AcceptPhone" ).val()
   var AcceptName = $( "#AcceptName" ).val();
   var AcceptAddress = $( "#AcceptAddress" ).val();
   var idCard =$( "#IdCard" ).val();
   var myObject = { 
"SenderPhone" : SenderPhone, 
"SenderName" : SenderName ,
"SenderMobile" : SenderMobile,
"SenderAddress" : SenderAddress,
"AcceptMobile" : AcceptMobile, 
"AcceptPhone" : AcceptPhone, 
"AcceptName" : AcceptName,
   "AcceptAddress" : AcceptAddress,
   "idCard" : idCard}
// var obj＝{"SendPhone",SendPhone};
// obj["SendPhone"] = SendPhone;
// obj["SendName"] = SendName;
// obj["SenderMobile"] = SenderMobile;
// obj["AcceptMobile"] = AcceptMobile;
// obj["AcceptPhone"] = AcceptPhone;
// obj["AcceptName"] = AcceptName;
// obj["AcceptAddress"] = AcceptAddress;
   $.ajax( {
         url: "http://localhost:8080/A1_BILL/O2OOrder/saveClientInfo.do?callback=?&USER_NAME=WEM1&PASSWORD=1",
         // url: "http://10.16.170.37:8080/A1_INTE/benniaoOrder/benO2OOrder.do?callback=?&content="+encodeURI(encodeURI(strDetails)),
         data: {"JSONDATA":encodeURI(JSON.stringify(myObject))},
            type: 'POST',
            async: false,
            dataType: "json",
		    jsonp: "callback",//传递给请求处理程序或页面的，用以获得jsonp回调函数名的参数名(一般默认为:callback)
		    jsonpCallback:"callback",//自定义的jsonp回调函数名，默认未jquery自动生成的随机函数名，也可以写“?”jquery会自动处理
        	//crossDomain: true,
        	//scriptCharset: "utf-8",
            success: function (result)
            {
          
            }, 
            failed: function ()
            {
               
            }
        } )
}


//按钮选择情况
function ItemType( value )
{
    debugger;
    $( "#hiddenItemType" ).val( value );
    
}
//按钮选择情况
function ItemType2( value )
{
    debugger;
    var other = $( '#other' ).val()
    if ( other != null && other != "" && other != undefined )
    {
        debugger;
        if ( other.length <= 10 )
        {
            $( "#hiddenItemType" ).val( value );
        } else
        {
            layer.alert( "最多十个字段" );
        }

    }

}
/*
 * 提交验证，非空验证，部分正则验证
 * type = 0  //手机验证
 * type = 1 //电话验证
 * type = 2 //数字验证
 * type = 3 //网址验证
 * type = 4 //邮箱验证
 * type = 5 //密码验证
 * type = 6 //qq验证
 * type = 7 //身份证号验证
 * count：允许输入字符数
 * erro_text：错误提示信息
 */
function InputVCheck(inputId,type,count){
    var $inputId = $('#'+inputId), $inputP = $inputId.parent(), $erroBox = $('#'+inputId+'_erro'); //元素选择
    var inputV = $inputId.val(), reg = '', erro_text = '', isNull = '', inputVLen = '', type_text;     //输入框的值
    var placeV = $inputId.attr('placeholder')||'';
    inputV = (placeV!=''&& inputV==placeV)?'':inputV;
    var inputV = inputV.replace(/\s+/g,"");   //去除空格
    switch (type){
        case -1:
            type_text='指定内容';
            erro_text='* 请按规则输入';
            break;
        case 0:
            /// reg=/^[0-9]{11}$/;
            reg = /^0?(13[0-9]|15[012356789]|17[0678]|18[0-9]|14[57])[0-9]{8}$/;
            type_text='手机号码';
            erro_text='* 手机号码格式不正确';
            break;
        case 1:
            reg=/^(\d{3}-)(\d{8})$|^(\d{3})(\d{8})$|^(\d{4}-)(\d{7})$|^(\d{4}-)(\d{8})$|^(\d{4})(\d{8})$/;
            type_text='电话号码';
            erro_text='* 电话格式不正确；例：021-12345678';
            break;
        case 2:
            reg=/^(([0-9]{1,2}(\.[0-9]{1,2})?)|(100))$/;
            type_text='数字';
            erro_text='* 请输入小于100的数字，最多两位小数；例：11.11';
            break;
        case 3:
            reg=/((((^https?)|(^ftp)):\/\/)?([\-\w]+\.)+\w{2,3}(\/[%\-\w]+(\.\w{2,})?)*(([\w\-\.\?\\\/+@&#;`~=%!]*)(\.\w{2,})?)*\/?)/i;
            type_text='网址';
            erro_text='* 网址格式不正确；例：http://www.lizi.com';
            break;
        case 4:
            reg=/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
            type_text='邮箱';
            erro_text='* 邮箱格式不正确；例：abc@163.com';
            break;
        case 5:
            reg=/^[A-Za-z0-9]+$/;
            type_text='密码';
            erro_text='* 必须由6-16位英文或数字组成';
            break;
        case 6:
            reg=/^[1-9]*[1-9][0-9]*$/;
            type_text='腾讯QQ';
            erro_text='* QQ格式不正确';
            break;
        case 7:
            reg=/^(\d{15}$|^\d{18}$|^\d{17}(\d|X|x))$/;
            type_text='身份证号';
            erro_text='* 身份证号格式不正确';
            break;    
        default:
            break;
    }
    if(inputV == ''){  //为空
        isNull=$inputId.attr('isnull');
        if(isNull=='no'){   //不允许为空
            $inputP.addClass('ui-erro');
            erro_text='* 请输入'+type_text;
            $erroBox.text(erro_text).show();
            return false;
        }else{           //允许为空
            $erroBox.text('').hide();
            return true;
        }
    }else{
        /*最大输入限制*/
        inputVLen = inputV.length;
        if(inputVLen > count){
            inputV = inputV.substring(0,count);
            $inputId.val(inputV);
        }
        var objExp=new RegExp(reg); //正则对象
        if(objExp.test(inputV)){
            $erroBox.html('').hide();
            if(type==5){  //密码验证
                if(LimitChar(inputV,6,16)){
                    var pasinfo=matchSame('password');
                    if(pasinfo=='same'){
                        return true;
                    }else{
                        $('#password_re_erro').html(pasinfo).show();
                        return false;
                    }

                }else{
                    $inputP.addClass('ui-erro');
                    $erroBox.text(erro_text).show();
                    return false;
                }
            }else{
                return true;
            }

        }else{
            $inputP.addClass('ui-erro');
            $erroBox.html(erro_text).show();
            return false;
        }
    }
}
